﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_HomePage_ctrProductHome : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage() - 1;
    private int nDefaultLang = Support.GetDefaultLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindData();
        }
    }


    private void BindData()
    {
        int nTrademark = 0;
        int nMaterial = 0;
        double dPriceFrom = 0;
        double dPriceTo = 100000000;
        string sProductName = "";
        int nStatus = 1;
        int nPageCount = 0;
        int nItemView = 12;
        int nItemID = 0;
        int isSaleOff = -1;
        int nPageIndex = 1;
        int nPageSize = 12;
        Products objProduct = new Products();
        DataTable dtbProduct = new DataTable();
        dtbProduct = objProduct.Search(nItemView, "", sProductName, nItemID, string.Empty, nTrademark, nMaterial, dPriceFrom, dPriceTo, isSaleOff, -1, nStatus, 0, 0, 0, nDefaultLang, nCurrentLang, nPageIndex, nPageSize, ref nPageCount);
        rptProduct.DataSource = dtbProduct;
        rptProduct.DataBind();


    }

    protected void rptProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {

            Image imgProduct = (Image)e.Item.FindControl("imgProduct");
            HyperLink lnkProduct = (HyperLink)e.Item.FindControl("lnkProduct");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "ProductID"));
            string imgName = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ImageDefault"));
            string productName = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductName_Default"));
            if (imgName == "")
            {
              imgProduct.ImageUrl =  Config.ROOT + Config.IMAGE_NO_IMAGE_FRONTEND;
            }
            else {
                imgProduct.ImageUrl = Config.ROOT + Config.IMAGE_PRODUCT_DEFAULT_UPLOAD + imgName;
                imgProduct.ToolTip = productName;
            }
            lnkProduct.NavigateUrl = Config.ROOT + Pages.FrontEnds.PRODUCT_DETAILS + "?" + Config.PAGE_ID + "=" + nID;
            
            //btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsID"));
        }
    }
}